<template>
	<view class="content">

		<!-- 有订单 -->
		<view v-if="list.length" class="orderlist">
			<view class="order" v-for="(item,index) in list" :key="index">
				<view class="header flex">
					<view>订单状态</view>
					<view :class="[item.state=='已发货' || item.state=='已退款'? 'red' : '',item.state=='已签收' ? 'blue' : '',]">{{item.state}}</view>
				</view>
				<view class="body flex">
					<view>车牌号:{{item.carbrand}}</view>
					<view>¥{{item.price}}</view>
				</view>

				<view class="footer flex" @tap="caop(item.logisticcode)">
					<view class="time">{{item.time}}</view>
					<view class="red">复制物流单号</view>
				</view>

				<view v-if="item.state=='已退款'">
					<view>驳回理由：</view>
					<view class="refuse">{{item.refuse}}</view>
				</view>
			</view>
		</view>


		<!-- 无订单 -->
		<view v-else class="nodata">
			<view class="fonticon icon">
				&#xe602;
			</view>
			<view class="txt">
				暂无订单记录
			</view>
		</view>
	</view>
</template>

<script>
	// 接口相关
	import _function from '@/common/_function.js'
	import api from '@/common/api.js'

	export default {
		data() {
			return {
				list: []
			};
		},
		methods: {
			caop(logisticcode) {
				uni.setClipboardData({
					data: logisticcode,
					success: function() {
						uni.showModal({
							title: '复制成功',
							content: '是否跳转查询?',
							success: function(res) {
								if (res.confirm) {
									wx.navigateToMiniProgram({
										appId: 'wx63e410bc2c6a792e',
										success(res) {
											wx.showToast({
												title: '跳转成功'
											})
										},
										fail(e){
											console.log(e)
										}
									})
								} else if (res.cancel) {

								}
							}
						})

					},
					fail() {
						uni.showToast({
							title: '复制失败!',
							duration: 2000,
							icon: 'none'
						})
					}
				});
			}
			// logistics(id, state, name,refuse,logisticcode) {

			// 	if (name != '') {
			// 		if(state=="已退款"){
			// 			uni.showModal({
			// 			    title: '提示',
			// 			    content: "驳回的原因:"+refuse,
			// 				showCancel:false,
			// 			    success: function (res) {

			// 			    }
			// 			})
			// 			return false
			// 		}

			// 		// uni.navigateTo({
			// 		// 	url: `../logistics/logistics?id=${id}&state=${state}&logisticcode=${logisticcode}`
			// 		// })
			// 	} else {
			// 		// uni.navigateTo({
			// 		// 	url: `../perfectinfo/perfectinfo?orderid=${id}`
			// 		// })
			// 	}

			// }
		},

		async onShow() {
			const res = await _function.request(api.myorder)

			if (res.data.code == 200) {
				if (res.data.data != 'null') {
					res.data.data.forEach(item => {
						switch (item.state) {
							case '0':
								item.state = '未付款'
								break
							case '1':
								item.state = '已付款'
								break
							case '2':
								item.state = '已发货'
								break
							case '3':
								item.state = '已签收'
								break
							case '4':
								item.state = '已退款'
								break
						}
					})
					this.list = res.data.data
				}
			}
		}
	}
</script>

<style lang="scss">
	page {
		height: 100%;
	}

	.content {
		height: 100%;

		.orderlist {
			padding: 20rpx;
			box-sizing: border-box;

			.order {
				display: flex;
				flex-direction: column;
				justify-content: space-between;
				margin: 10rpx 0;
				padding: 20rpx;
				background-color: #fff;
				border-radius: 10rpx;
				border: 2rpx solid #f0f0f0;


				.flex {
					display: flex;
					justify-content: space-between;
					align-items: center;
					padding: 10rpx 0;
				}


				.header {
					font-size: 28rpx;

				}

				.body {
					font-size: 32rpx;
				}

				.footer {
					.time {
						color: #666;
					}
				}
			}
		}


		.nodata {
			height: 100%;
			display: flex;
			justify-content: center;
			align-items: center;

			.icon {
				font-size: 80rpx;
			}

			.txt {
				font-size: 40rpx;
			}
		}
	}

	.red {
		color: red;
	}

	.blue {
		color: #007AFF;
	}
</style>
